package com.example.zg.ui_demo.recyclerview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.zg.ui_demo.R;

import java.util.ArrayList;
import java.util.List;

public class RecyclerviewActivity extends AppCompatActivity{
    private List<DataItem> dateItemList;
    RecyclerView recyclerView;
    Context context;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recyclerview);

        context=RecyclerviewActivity.this;

        RecyclerViewAdapter viewAdapter = new RecyclerViewAdapter();

        viewAdapter.setData(getDate());

        recyclerView = findViewById(R.id.recyclerView);

        //布局管理器  可以设置显示数据的方式为垂直或者水平
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);




        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(viewAdapter);

        //添加 Android内部提供的 默认水平分割线
        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));


    }

    private List<DataItem> getDate() {
        List<DataItem> dateItemList = new ArrayList<>();

        for(int i=0;i<50;i++)
        {
            DataItem dateItem = new DataItem();

            dateItem.setUrl("image"+i);
            dateItem.setText1("Text1："+i);
            dateItem.setText2("Text2："+i);

            dateItemList.add(dateItem);
        }

        return dateItemList;
    }

}
